<?php

namespace App\Http\Controllers\shop;

use Illuminate\Http\Request;
use App\Model\AdminUserModel;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;

//主页
class IndexController extends Controller
{
//	public function index(Request $request)
//	{
//		$auModel = new AdminUserModel;//管理员表
//		$res = $auModel->where('id',session('shop_id')->get();
//		dd($res);
//		return view('shop.index');
//	}
	public function index(){
		$id = session('shop_id');

		$res = AdminUserModel::where('id',$id)->first();
//		dd($res);
		return view('shop.index',compact('res'));
	}

	// 首页
	public function home(Request $request)
	{
		return view('admin.home');
	}

	public function info()
	{

	}

	//修改密码
	public function edit(){
		return view('shop.edit');
	}

	//修改
	public function edit_pass(){
		$id = session('shop_id');
		$list = AdminUserModel::where('id',$id)->first();
		if($list['password'] != passEncryp(request()->pass_o)){
			return ['code'=>0,'msg'=>'原密码有误'];
		}

		DB::beginTransaction();
		try{
			AdminUserModel::where('id',$id)->update([
				'password' => passEncryp(request()->pass_n),
			]);
			DB::commit();
		}catch(Exception $e){
			DB::rollBack();
		}
		return ['code'=>0,'msg'=>'更改成功'];
	}


}
